<template>
    <el-scrollbar :height="scrollHeight?scrollHeight:isTagsview ? `calc(100vh - 154px)` : `calc(100vh - 120px)`">
        <div>
            <zh-form ref="formRef" style="width: 96%" :md="12" :lg="12" :xl="12" :model="functionInfo" :rules="rules"
                     label-width="200px">
                <zh-form-input prop="funcId" label="功能ID" placeholder="" v-model="functionInfo.funcId"
                               disabled></zh-form-input>
                <zh-form-input prop="funcCode" label="功能编号" placeholder=""
                               v-model="functionInfo.funcCode"></zh-form-input>
                <zh-form-input prop="funcTitle" label="功能标题" placeholder=""
                               v-model="functionInfo.funcTitle"></zh-form-input>
                <zh-form-select
                    prop="nodeType"
                    label="节点类型"
                    :options="state.dictData.nodeType"
                    placeholder="请选择"
                    v-model="functionInfo.nodeType"
                ></zh-form-select>
                <zh-form-select
                    prop="funcType"
                    label="功能类型"
                    :options="state.dictData.funcType"
                    placeholder="请选择"
                    v-model="functionInfo.funcType"
                ></zh-form-select>
                <zh-form-select
                    prop="funcSourceType"
                    label="功能来源"
                    :options="state.funcSourceTypeOpt"
                    placeholder="请选择"
                    v-model="functionInfo.funcSourceType"
                ></zh-form-select>
                <zh-form-input prop="serviceName" label="服务名" placeholder="注册到注册中心的服务名"
                               v-model="functionInfo.serviceName"></zh-form-input>
                <zh-form-input prop="qps" label="每秒调用量" placeholder="调用频次每秒并发调用量"
                               v-model="functionInfo.qps"></zh-form-input>
                <zh-form-input prop="parentTitle" label="父功能标题" placeholder=""
                               v-model="functionInfo.parentTitle"></zh-form-input>
                <zh-form-select
                  prop="appId"
                  :lazy="true"
                  label="所属应用"
                  v-model="functionInfo.appId"
                  :fieldNames="{ label: 'appName', value: 'appId' }"
                  funcCode="application0012"
                  searchField="appName"
                  :timeout="20000"
                  @change="appIdChange"
                ></zh-form-select>
                <zh-form-select
                    prop="envId"
                    label="应用环境"
                    :options="state.envDict"
                    placeholder="应用环境"
                    v-model="functionInfo.envId"
                ></zh-form-select>
                <zh-form-input prop="classPath" label="所属类名" placeholder=""
                               v-model="functionInfo.classPath"></zh-form-input>
                <zh-form-input prop="method" label="功能方法" placeholder="" v-model="functionInfo.method"></zh-form-input>
                <zh-form-input prop="orderNo" label="排序" placeholder="" v-model="functionInfo.orderNo"
                               :disabled="true"></zh-form-input>
                <zh-form-select
                    prop="operating"
                    label="操作期"
                    :options="state.dictData.operating"
                    placeholder="请选择"
                    v-model="functionInfo.operating"
                ></zh-form-select>
                <zh-form-select
                    prop="auType"
                    label="流程节点类型"
                    :options="state.dictData.auType"
                    placeholder="请选择"
                    v-model="functionInfo.auType"
                ></zh-form-select>
                <zh-form-input prop="nextFuncCode" label="下级调用功能" placeholder="下一级调用功能编号"
                               v-model="functionInfo.nextFuncCode"></zh-form-input>
                <zh-form-select
                    prop="orgId"
                    label="所属单位"
                    :options="state.orgDict"
                    placeholder="请选择所属单位"
                    :timeout="20000"
                    v-model="functionInfo.orgId"
                ></zh-form-select>
                <zh-form-select
                    prop="devOrgId"
                    label="所属开发公司"
                    :options="state.devOrgDict"
                    placeholder="请选择所属开发公司"
                    v-model="functionInfo.devOrgId"
                ></zh-form-select>
                <zh-form-input prop="pathFunc" label="url路径" placeholder="http的url路径，webservice·的方法名"
                               v-model="functionInfo.pathFunc"></zh-form-input>
                <zh-form-select
                    prop="httpMethod"
                    label="调用方式"
                    :options="[{dictKey:'get',dictValue:'get'},{dictKey:'post',dictValue:'post'}]"
                    placeholder="请选择调用方式"
                    v-model="functionInfo.httpMethod"
                ></zh-form-select>
                <zh-form-input prop="timeout" label="服务超时时间" placeholder="服务超时时间(秒)"
                               v-model="functionInfo.timeout"></zh-form-input>
                <zh-form-input prop="begDate" label="开始时间" placeholder="服务有效开始时间"
                               v-model="functionInfo.begDate"></zh-form-input>
                <zh-form-input prop="endDate" label="结束时间" placeholder="服务有效结束时间"
                               v-model="functionInfo.endDate"></zh-form-input>
                <zh-form-input prop="visits" label="每日次数" placeholder="每日访问上限次数"
                               v-model="functionInfo.visits"></zh-form-input>
                <zh-form-select
                    prop="customCharset"
                    label="自定义字符集"
                    :options="state.dictData.charset"
                    placeholder="请选择自定义字符集,默认为utf-8"
                    v-model="functionInfo.customCharset"
                ></zh-form-select>
                <zh-form-select
                    prop="contentType"
                    label="请求类型"
                    :options="state.dictData.httpContentType"
                    placeholder="请选择请求类型"
                    v-model="functionInfo.contentType"
                ></zh-form-select>
                <zh-form-input prop="customClass" label="自定义处理类" placeholder="自定义处理类 需要注入"
                               v-model="functionInfo.customClass"></zh-form-input>
                <zh-form-input prop="begDate" label="每日开始时间" placeholder="每日可调用开始时间"
                               v-model="functionInfo.callBegTime"></zh-form-input>
                <zh-form-input prop="endDate" label="每日结束时间" placeholder="每日可调用结束时间"
                               v-model="functionInfo.endDate"></zh-form-input>
                <zh-form-select
                    prop="webMoreFlag"
                    label="webservice是否多参数"
                    :options="state.dictData.flag"
                    placeholder="webservice入参是否多参数"
                    v-model="functionInfo.webMoreFlag"
                ></zh-form-select>
                <zh-form-input prop="callCalendarId" label="调用规则日历" placeholder="调用规则日历"
                               v-model="functionInfo.callCalendarId"></zh-form-input>
                <zh-form-select
                    prop="interfaceStatus"
                    label="接口状态"
                    :options="state.dictData.interfaceStatus"
                    placeholder="接口状态"
                    v-model="functionInfo.interfaceStatus"
                ></zh-form-select>
                <zh-form-select
                    prop="sendStatus"
                    label="发送状态"
                    :options="state.dictData.sendStatus"
                    placeholder="发送状态"
                    v-model="functionInfo.sendStatus"
                ></zh-form-select>
                <zh-form-select
                    prop="networkType"
                    label="对外访问网络类型"
                    :options="state.dictData.networkType"
                    placeholder="对外访问网络类型"
                    v-model="functionInfo.networkType"
                ></zh-form-select>
                <zh-form-select
                    prop="otherAccessFlag"
                    label="是否对第三方应用开放"
                    :options="state.dictData.flag"
                    placeholder="是否对第三方应用开放"
                    v-model="functionInfo.otherAccessFlag"
                ></zh-form-select>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否启用"
                    prop="funcStatus"
                    v-model="functionInfo.funcStatus"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否分发接口"
                    prop="distributedFlag"
                    v-model="functionInfo.distributedFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否组合接口"
                    prop="composeFlag"
                    v-model="functionInfo.composeFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="申请是否需审核"
                    prop="authFlag"
                    v-model="functionInfo.authFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否需要转义"
                    prop="isEncode"
                    v-model="functionInfo.isEncode"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否公共"
                    prop="publicFlag"
                    v-model="functionInfo.publicFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否可回退"
                    prop="rollbackFlag"
                    v-model="functionInfo.rollbackFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="跨业务期回退"
                    prop="spanRollbackFlag"
                    v-model="functionInfo.spanRollbackFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="是否开启流程"
                    prop="auditFlag"
                    v-model="functionInfo.auditFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-radio
                    :sm="12"
                    :lg="8"
                    :xl="8"
                    label="记日志"
                    prop="logFlag"
                    v-model="functionInfo.logFlag"
                    :options="state.dictData.flag"
                ></zh-form-radio>
                <zh-form-input
                    prop="api"
                    :span="24"
                    label="api"
                    type="textarea"
                    placeholder="api http的url路径，webservice·的方法名"
                    v-model="functionInfo.api"
                ></zh-form-input>
                <zh-form-input
                    prop="classPath"
                    :span="24"
                    label="类路径"
                    type="textarea"
                    placeholder="类路径"
                    v-model="functionInfo.classPath"
                ></zh-form-input>
                <zh-form-input
                    prop="method"
                    :span="24"
                    label="请求方法"
                    type="textarea"
                    placeholder="请求方法"
                    v-model="functionInfo.method"
                ></zh-form-input>
                <zh-form-input
                    prop="funcDesc"
                    :span="24"
                    label="功能描述"
                    type="textarea"
                    placeholder="功能描述"
                    v-model="functionInfo.funcDesc"
                ></zh-form-input>
                <zh-form-input
                    prop="remarks"
                    :span="24"
                    label="摘要信息"
                    type="textarea"
                    placeholder="JSONArray格式，操作日志使用，优先使用功能里的摘要，为空则使用路由里的摘要"
                    v-model="functionInfo.remarks"
                ></zh-form-input>
            </zh-form>
        </div>
    </el-scrollbar>
</template>

<script lang="ts" setup name="FunctionForm">
import {FormInstance} from 'element-plus';
//------------------接收传入参数------------------------
const props = defineProps({
    scrollHeight: {
        type: String,
        default: ''
    }
});

//------------------定义子组件---------------------------
const formRef = ref<FormInstance>();

//------------------内部变量定义-------------------------
const state = reactive({
    hideChecked: false,
    confirmLoading: false,
    dictData: {} as any,
    initData: {},
    funcSourceTypeOpt: [
        {dictKey: '1', dictValue: '内部服务'},
        {dictKey: '2', dictValue: '第三方应用接入'}
    ],
    appDict: [],
    orgDict: [],
    devOrgDict: [],
    envDict: []
});
const rules = reactive({
    nodeType: [
        {
            required: true,
            message: '请输入节点类型',
            trigger: 'blur',
        },
    ],
    funcSourceType: [
        {
            required: true,
            message: '请输入功能来源类型',
            trigger: 'blur',
        },
    ],
    funcStatus: [
        {
            required: true,
            message: '请输入状态',
            trigger: 'blur',
        },
    ],
    publicFlag: [
        {
            required: true,
            message: '请输入是否公共',
            trigger: 'blur',
        },
    ],
    timeout: [
        {
            required: true,
            message: '请输入是否超时时间',
            trigger: 'blur',
        }
    ],
    pathFunc: [
        {
            required: true,
            message: '请输入接口路径',
            trigger: 'blur',
        }
    ],
    visits: [
        {
            required: true,
            message: '请输入每日访问上限次数',
            trigger: 'blur',
        }
    ],
    isEncode: [
        {
            required: true,
            message: '请输入是否需要转义',
            trigger: 'blur',
        }
    ]
});
const functionInfo = ref<any>({});
const {isTagsview} = storeToRefs($store.theme);

//------------------定义调用方法-------------------------
function setInitDate(info) {
    formRef.value?.resetFields();
    if (info) {
        functionInfo.value = info;
    }
}

function appIdChange(e) {
    if (e) {
        $api.common.send.post('apiAppEnv0007',{appId: e}).then(res => {
            if (res.result) {
                state.envDict = res.result
            }
        }).catch(e => {

        });
    } else {
        state.envDict = [];
    }
}

//------------------初始化------------------------------
const params = {
    dictFields: 'auType,operating,nodeType,funcType,flag,charset,httpContentType,interfaceStatus,sendStatus,networkType',
};
$api.common.getBatchDict.post(params).then((res) => {
    state.dictData = res.result;
});
$api.common.send.post('application0011', {}).then((res) => {
    state.appDict = res.result;
});
$api.common.send.post('org0019', {orgType: '01'}).then((res) => {
    state.orgDict = res.result;
});
$api.common.send.post('org0019', {orgType: '0201'}).then((res) => {
    state.devOrgDict = res.result;
});


//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({setInitDate, form: formRef, functionInfo});
</script>
